package com.gxa.wmcrm.Actionnew;

import com.gxa.wmcrm.entity.Code;
import com.gxa.wmcrm.pojo.LoginEntity;
import com.gxa.wmcrm.service.Impl.UserServiceNewImpl;
import com.gxa.wmcrm.service.UserServiceNew;
import org.apache.struts2.ServletActionContext;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

import static com.opensymphony.xwork2.Action.SUCCESS;

public class LoginAction {

    // 用户名，密码，用户输入的验证码，系统验证码
    private String username;
    private String password;
    private String Usercode;
    private String AdminCode;

    // 准备返回数据 - Map
    private Map<String, Object> resultMap;

    public Map<String, Object> getResultMap() {
        return resultMap;
    }

    public String execute() {
        return SUCCESS;
    }

    public String login() {

        HttpServletRequest request = ServletActionContext.getRequest();
        Map<String, String[]> parameterMap = request.getParameterMap();

        username = parameterMap.get("login")[0];
        password = parameterMap.get("pwd")[0];
        Usercode = parameterMap.get("code")[0];
        AdminCode = parameterMap.get("AdminCode")[0];


        // 实体类封装
        LoginEntity loginEntity = new LoginEntity();
        loginEntity.setUsername(username);
        loginEntity.setPassword(password);

        Code code = new Code();
        code.setCode(Usercode);
        code.setAdminCode(AdminCode);

        // 准备返回数据 - Map
        resultMap = new HashMap<>();
        UserServiceNew userServiceNew = new UserServiceNewImpl();
        resultMap = userServiceNew.login(loginEntity,code);

/*        1. action   service   dao  分工清楚  责任明确   开发效率高  设计的思想
                 2 接口 实现类  java的思想*/

        return SUCCESS;
    }


}
